/**
 * 
 */
package com.itboye.allshengmedical.sci.packet.resp;

/**
 * @author 贝贝 346551990@qq.com
 * @date 2016-12-9
 */
public class VersionRespPacket extends BaseRespPacket {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3192089881804277183L;
	BaseRespPacket packet;

	public VersionRespPacket(BaseRespPacket packet) {
		this.clone(packet);
		this.packet = packet;
		this.setExpectDataLength(6);
	}

	private byte get(int index) {
		// for (int i = 0; i < packet.getContent().length; i++) {
		// Log.e("hu  " + i,
		// Integer.parseInt(packet.getContent()[index] + "", 16) + "");
		// }
		return packet.getContent()[index];
	}

	/**
	 * 获取版本信息
	 * 
	 * @return
	 */
	public String getVersion() {
		int version = 0;
		StringBuilder builder = new StringBuilder();
		if (packet.isLegalContent()) {
			builder.append(get(1));
			builder.append(get(2));
			version = Integer.parseInt(builder.toString());
		}

		return version + "";
	}

	/**
	 * 获取时间信息
	 * 
	 * @return
	 */
	public String getTime() {

		StringBuilder time = new StringBuilder();
		if (isLegalContent()) {
			time.append("20" + get(3) + "-");
			time.append(get(4) + "-");
			time.append(get(5) + "");
		}

		return time.toString();
	}

	public static void main(String[] args) {
		String versionHex = "5AA5060C010000000000133EE3";
		BaseRespPacket packet = RespPacketParser.parse(versionHex);
		System.out.println("数据包sum值: " + packet.sumLenAndContent());
		System.out.println("是否合法数据包: " + packet.isValidPack());
		System.out.println("数据包类型: " + packet.getCmdType());

		System.out.println(": " + packet.getCmdType());
	}

}
